<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <%@include file="../../common.jsp"%>
    <title>巡检任务回执录入</title>
</head>
<body>
<h2>巡检任务回执</h2>
<hr>
<div class="bottom">
    <form class="layui-form" lay-filter="poleForm" id="poleForm" action="" style="padding:15px 10px;">
        <div class="layui-container">
            <div class="layui-row">
                <div class="layui-col-xs3">
                    <div class="grid-demo grid-demo-bg1">
                        <div class="layui-form-item">
                            <div class="layui-input-inline">
                                <select name="lineId" id="line" width="300px" lay-filter="line">
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs9">
                    <div class="grid-demo">
                        <input type="hidden" name="id">
                        <input type="hidden" name="taskId">
                        <div class="layui-form-item">
                            <label class="layui-form-label">线路编码:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="lineCode" required readonly  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                            <label class="layui-form-label">杆塔编号:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="poleCode" required readonly  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">缺陷类型:</label>
                            <div class="layui-input-inline">
                                <select name="bugTypeId" lay-filter="bugType" id="bugType">
                                    <option value="-1">请选择</option>
                                </select>
                            </div>
                            <label class="layui-form-label">缺陷级别:</label>
                            <div class="layui-input-inline">
                                <select name="bugLevelId" lay-filter="bugLevel" id="bugLevel">
                                    <option value="-1">请选择</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">完好率:</label>
                            <div class="layui-input-block">
                                <input type="text" name="intactRate" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">发现时间:</label>
                            <div class="layui-input-block">
                                <input type="text" name="time" required value="" readonly lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">发现人:</label>
                            <div class="layui-input-block">
                                <input type="text" name="discovererName" required readonly value="${sessionScope.login_user.username}"  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">缺陷描述:</label>
                            <div class="layui-input-block">
                                <input type="text" name="bugDesc" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div>
            <button type="button" class="layui-btn layui-btn-normal" onclick="upload()">上传回执</button>
            <button type="button" class="layui-btn layui-btn-normal" onclick="save()">保存</button>
            <button type="button" class="layui-btn layui-btn-normal" onclick="fanhui()">返回</button>
        </div>
    </form>
</div>
<script>

    //缺陷类型下拉框
    $.get("${path}/taskReturn/getBugType",function (data) {
        $.each(data,function () {
            var option = $('<option></option>').appendTo("#bugType");
            option.text(this.configValueName).val(this.configValueId);
        });
    });
    //缺陷级别下拉框
    $.get("${path}/taskReturn/getBugLevel",function (data) {
        $.each(data,function () {
            var option = $('<option></option>').appendTo("#bugLevel");
            option.text(this.configValueName).val(this.configValueId);
        });
    });
    //获取当前时间
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }

    //返回上一级页面
    function fanhui(){
        history.go(-1);
    }
    //杆塔编号
    var poleId;
    layui.use(["form","table"],function () {
        $.get("/task/get",{"taskId":${sessionScope.taskId}},function (data) {
            var lineName = data.lineName;//线路名称
            layui.form.val("poleForm",data)
            people = data.issuedByName;
            time = data.issuedTime;
            //完成时间
            if(data.finishTime == null){
                $(":input[name = 'finishTime']").val("尚未完成");
            }
            //根据线路编号,查询巡检员
            $.get("/taskDetail/getTaskId",{"taskId":data.id},function (data) {
                var inspectors = "";
                $.each(data,function () {
                    inspectors = inspectors + this.inspectorName+",";
                })
                $(":input[name = 'inspectors']").val(inspectors);
            })

            //赋值线路杆塔
            $.get("${path}/taskDetail/getLinePole",{"lineId":data.lineId},function (data) {
                //第一个为线路名称
                var option = $('<option></option>').appendTo("#line");
                option.text(lineName);
                //查询杆塔缺陷表
                $.get("/taskDetail/getInspectaskForTaskId",{"taskId":${sessionScope.taskId}},function (inspectionDetial) {
                        $.each(inspectionDetial,function () {
                            if(this.bugTypeName != "" && this.bugTypeName != null){
                                var option = $('<option></option>').appendTo("#line");
                                option.text(this.poleCode+"(已回执)").val(this.poleId);
                            }else{
                                var option = $('<option></option>').appendTo("#line");
                                option.text(this.poleCode).val(this.poleId);
                            }
                        })
                    layui.form.render();
                })


            });
        })
        //下拉框选择事件
        layui.form.on('select(line)', function(data){
            poleId = data.value;
            //根据杆塔编号查询杆塔信息
            $.get("/task/getPole",{"poleId":poleId},function (data) {
                layui.form.val("poleForm",data);
                //发现人
                $(":input[name = 'discovererName']").val('${sessionScope.login_user.username}');
                //下发时间
                $(":input[name = 'time']").val(getNowFormatDate());
            })
        });
    })

    //保存
    function save() {
        //保存缺陷信息
        if(poleId == null || poleId == 0){
            alert("请选择杆塔");
        }else{
            //获取表单数据
            var params = $("#poleForm").serialize();
            //修改缺陷信息
            $.get("/taskReturn/updateTaskInfo",params,function (data) {
                if(data){
                    layer.msg('保存成功!',{icon:1})
                }
            })
        }
    }

    //上传回执
    function upload() {
        //获取表单信息
        //修改缺陷信息
        $.get("/taskReturn/upload",{"taskId":${sessionScope.taskId}},function (data) {
            if(data){
                layer.msg('上传回执成功!',{icon:1})
                var t=setTimeout(fanhui(),1000);
            }
        })
    }


</script>
</body>
</html>